<!-- 教程管理 -->
<template>
  <div class="page-box h100 display-flex czbj">
    <p class="title-label mb10">教程管理</p>
    <!-- sonRouter="yybureauFormationBJ" 为跳转新的页面编辑 -->
    <dxtable
      :dataJson="dataJson"
      :portUrl="portUrl"
      :formJson="formJson"
      :qx="qx"
      imgkuTitle="课程"
      accept=".jpg,.png,,.jpeg,.mp4,.m4v"
      ref="databale"
    ></dxtable>
  </div>
</template>
<script lang="ts" setup>
import dxtable from "../../components/util/dxtable.vue";
import sort from "../../components/util/sort.vue";
import { dxget, dxpost } from "../../util/index";
import { NButton, NImage, NTag, NSwitch } from "naive-ui";
import { h, ref, reactive, render } from "vue";
const databale = ref();
const initeer = () => {
  databale.value.initDataExpose();
};
const portUrl = "jyc/tutorialmanagement/tutorialmanagement";
let dataJson = [
  {
    title: "教程名称",
    span: 24,
    key: "title",
    width: "",
    search: true,
    istable: true,
    required: false,
  },
  {
    title: "分类",
    type: "select",
    options: [],
    span: 12,
    key: "fenleiid",
    width: "200",
    search: true,
    istable: true,
    render: (row) => {
    
     try{
      return dataJson[1].options.filter((a) => a.value == row.fenleiid)[0]
      .label;
     }catch(e){
      return '-'
     }
    },
  },
  {
    title: "单价",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "danjia",
    width: "200",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "已售",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "yishou",
    width: "200",
    search: false,
    istable: true,
    required: false,
    render(row){
      return row.yishou||0
    }
  },
  {
    title: "排序",
    width: 100,
    render: (row) => {
      row.sjk = "jyc"; //数据库
      row.databaseName = "tutorialmanagement"; //表名
      return h(sort, {
        row,
        onCallBack: () => {
          initeer();
        },
      });
    },
  },
  {
    title: "添加时间",
    key: "addTime",
    width: 150,
  },
];

const qx = {
  DeletePermissionID: "jyctutorialmanagementdel", //删除
  EditPermissionIdentifier: "jyctutorialmanagementbj", // 编辑
  NewPermissionIdentifier: "jyctutorialmanagementxz", // 新建
  ViewPermissionID: "jyctutorialmanagementck", // 查看
};


let formJson = reactive([
  {
    title: "教程名称",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 24,
    key: "title",
    width: "",
    search: false,
    istable: true,
    required: true,
  },
  {
    title: "分类",
    type: "select",
    options: [],
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "fenleiid",
    width: "",
    search: false,
    istable: true,
    required: true,
  },
  {
    title: "单价",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "danjia",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "封面",
    type: "img",
    val: "",
    icon: "dx-img",
    span: 12,
    key: "cover",
    width: "",
    search: false,
    istable: true,
    required: false,
  },{
    title: "试看视频",
    type: "videocover",
    val: "",
    icon: "dx-img",
    span: 12,
    key: "shikan",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "视频地址",
    type: "videoList",
    val: [],
    icon: "dx-ai-img-list",
    span: 12,
    key: "url",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "教程详情",
    type: "fwb",
    val: "",
    icon: "dx-m-fuwenben",
    span: 24,
    key: "fwnr",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
]);
const czFun = {
  fun: (row) => {
    return [
      h(
        NButton,
        {
          type: "info",
          quaternary: true,
          onClick: async (e) => {},
        },
        "复制代码"
      ),
    ];
  },
};

// 获取字典内容
const xtgxxmfl = async () => {
  const { data }: any = await dxget("dxgjAdmin/getzd", { name: "jycjcfenlei" });
  dataJson[1].options = [
    {
      label: "全部",
      value: "",
    },
    ...data,
  ];
  formJson[1].options = data;
  xmlxSelect.value = data;
  console.log(data);
};
xtgxxmfl();
</script>
<style scoped></style>
